/*
 * 
 */
package team.com.demo;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.KeyEvent;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import java.util.Calendar;
import java.util.HashSet;
import java.util.Iterator;
import javax.swing.DefaultListModel;
import java.net.InetAddress;
import java.util.ArrayList;

/**
 *
 * @author 李惠来（LiHuilai）<a href="http://blog.csdn.net/im1046061426">CSDN博客</a>
 * 邮箱：huilai475@163.com QQ：1046061426
 */
public class ChatUI extends javax.swing.JFrame {
    private Broadcast broadcast;
    private boolean flag=false;//提示信息两种颜色切换的标记
    private Document document;
    private String font="宋体";
    private int fontSize=14;
    private int style;
    private boolean italicFlag=false;//标记是否使用斜体
    private boolean boldFlag=false;//标记是否使用黑体
    /**
     * Creates new form ChatUI
     */
    public ChatUI() {
        initComponents();        
        setLocationRelativeTo(null);
    }

    public void setBroadcast(Broadcast broadcast){
        this.broadcast=broadcast;
        this.broadcast.setChatUI(this);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        onlineUsersJList = new javax.swing.JList();
        nicknameJTextField = new javax.swing.JTextField();
        inputMessageJScrollPane = new javax.swing.JScrollPane();
        inputMessageJTextPane = new javax.swing.JTextPane();
        sendJButton = new javax.swing.JButton();
        closeJButton = new javax.swing.JButton();
        flushJButton = new javax.swing.JButton();
        promptJLabel = new javax.swing.JLabel();
        showMessageJScrollPane = new javax.swing.JScrollPane();
        showMessageJTextPane = new javax.swing.JTextPane();
        fontSizeJComboBox = new javax.swing.JComboBox();
        fontJComboBox = new javax.swing.JComboBox();
        colorJComboBox = new javax.swing.JComboBox();
        italicJButton = new javax.swing.JButton();
        boldJButton = new javax.swing.JButton();
        sendToJButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setMinimumSize(new java.awt.Dimension(600, 420));
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        onlineUsersJList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "lihuilai(192.168.1.100)" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        onlineUsersJList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        onlineUsersJList.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        onlineUsersJList.setMaximumSize(new java.awt.Dimension(155, 51));
        onlineUsersJList.setMinimumSize(new java.awt.Dimension(155, 51));
        onlineUsersJList.setPreferredSize(new java.awt.Dimension(155, 51));
        jScrollPane1.setViewportView(onlineUsersJList);

        nicknameJTextField.setForeground(new java.awt.Color(255, 0, 0));
        nicknameJTextField.setText("输入姓名");
        nicknameJTextField.setToolTipText("姓名四个字以内，字母8个以内，按<Enter>键结束输入");
        nicknameJTextField.setAutoscrolls(false);
        nicknameJTextField.setMinimumSize(new java.awt.Dimension(100, 21));
        nicknameJTextField.setName(""); // NOI18N
        nicknameJTextField.setVerifyInputWhenFocusTarget(false);
        nicknameJTextField.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                nicknameJTextFieldFocusLost(evt);
            }
        });
        nicknameJTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                nicknameJTextFieldKeyPressed(evt);
            }
        });

        inputMessageJTextPane.setFont(new java.awt.Font("宋体", 0, 14)); // NOI18N
        inputMessageJScrollPane.setViewportView(inputMessageJTextPane);

        sendJButton.setText("群发");
        sendJButton.setToolTipText("快捷键Ctrl+Enter");
        sendJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sendJButtonActionPerformed(evt);
            }
        });

        closeJButton.setText("关闭");
        closeJButton.setToolTipText("快捷键Alt+F4");
        closeJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                closeJButtonActionPerformed(evt);
            }
        });

        flushJButton.setText("刷新");
        flushJButton.setToolTipText("刷新昵称，刷新用户列表，快捷键F5");
        flushJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                flushJButtonActionPerformed(evt);
            }
        });

        showMessageJTextPane.setEditable(false);
        showMessageJScrollPane.setViewportView(showMessageJTextPane);

        fontSizeJComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22" }));
        fontSizeJComboBox.setSelectedIndex(5);
        fontSizeJComboBox.setToolTipText("选择字体大小");
        fontSizeJComboBox.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                fontSizeJComboBoxItemStateChanged(evt);
            }
        });

        fontJComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "宋体", "楷体", "黑体" }));
        fontJComboBox.setToolTipText("选择字体");
        fontJComboBox.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                fontJComboBoxItemStateChanged(evt);
            }
        });

        colorJComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "黑色", "红色", "蓝色", "橙色", "绿色", "其它" }));
        colorJComboBox.setToolTipText("字体颜色");
        colorJComboBox.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                colorJComboBoxItemStateChanged(evt);
            }
        });

        italicJButton.setText("I");
        italicJButton.setToolTipText("斜体");
        italicJButton.setFocusable(false);
        italicJButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        italicJButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        italicJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                italicJButtonActionPerformed(evt);
            }
        });

        boldJButton.setText("B");
        boldJButton.setToolTipText("加粗");
        boldJButton.setFocusable(false);
        boldJButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        boldJButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        boldJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                boldJButtonActionPerformed(evt);
            }
        });

        sendToJButton.setText("发送");
        sendToJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sendToJButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelLayout = new javax.swing.GroupLayout(jPanel);
        jPanel.setLayout(jPanelLayout);
        jPanelLayout.setHorizontalGroup(
            jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelLayout.createSequentialGroup()
                .addGroup(jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanelLayout.createSequentialGroup()
                        .addComponent(nicknameJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(flushJButton))
                    .addComponent(jScrollPane1))
                .addGroup(jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(showMessageJScrollPane)
                            .addComponent(inputMessageJScrollPane)))
                    .addGroup(jPanelLayout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addComponent(fontJComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(fontSizeJComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(italicJButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(boldJButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(colorJComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
            .addGroup(jPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(promptJLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 75, Short.MAX_VALUE)
                .addComponent(closeJButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(sendToJButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(sendJButton)
                .addGap(8, 8, 8))
        );
        jPanelLayout.setVerticalGroup(
            jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelLayout.createSequentialGroup()
                .addGap(1, 1, 1)
                .addGroup(jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanelLayout.createSequentialGroup()
                        .addGroup(jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(nicknameJTextField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(flushJButton))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 361, Short.MAX_VALUE))
                    .addGroup(jPanelLayout.createSequentialGroup()
                        .addComponent(showMessageJScrollPane)
                        .addGap(8, 8, 8)
                        .addGroup(jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(italicJButton)
                            .addGroup(jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(fontJComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(fontSizeJComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(boldJButton)
                            .addComponent(colorJComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(inputMessageJScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(sendJButton)
                        .addComponent(closeJButton)
                        .addComponent(sendToJButton))
                    .addComponent(promptJLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void nicknameJTextFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_nicknameJTextFieldKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER){
            String nicknameTemp;
            nicknameTemp=this.nicknameJTextField.getText().trim();
            if (!nicknameTemp.equals("")){
                this.broadcast.setNickname(nicknameTemp);
                this.prompt("昵称设置成功");
                //未实现功能：把上面信息写入到日志文件 
                this.broadcast.online();
            }            
        }
    }//GEN-LAST:event_nicknameJTextFieldKeyPressed

    private void flushJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_flushJButtonActionPerformed
        String nicknameTemp;
        nicknameTemp=this.nicknameJTextField.getText().trim();
        this.broadcast.setNickname(nicknameTemp);
        this.prompt("昵称设置成功");
        this.broadcast.online();
    }//GEN-LAST:event_flushJButtonActionPerformed

    private void closeJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeJButtonActionPerformed
        this.broadcast.offline();
        System.exit(0);
    }//GEN-LAST:event_closeJButtonActionPerformed

    private void sendJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sendJButtonActionPerformed
        if (!this.inputMessageJTextPane.getText().equals("")){
            this.broadcast.sendMessages(this.inputMessageJTextPane.getText());
            this.inputMessageJTextPane.setText("");
        }        
    }//GEN-LAST:event_sendJButtonActionPerformed

    private void nicknameJTextFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_nicknameJTextFieldFocusLost
        String nicknameTemp;
        nicknameTemp=this.nicknameJTextField.getText().trim();
        if (!nicknameTemp.equals("输入姓名") & !nicknameTemp.equals(this.broadcast.getNickname()) & !nicknameTemp.equals("")){
            this.broadcast.setNickname(nicknameTemp);
            this.prompt("昵称设置成功");
            this.broadcast.online();
        }
        
        //未实现功能：把上面信息写入到日志文件
    }//GEN-LAST:event_nicknameJTextFieldFocusLost

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
          this.broadcast.offline();
    }//GEN-LAST:event_formWindowClosing

    private void fontJComboBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_fontJComboBoxItemStateChanged
        this.font=this.fontJComboBox.getSelectedItem().toString();
        this.inputMessageJTextPane.setFont(new Font(font,style,fontSize));
        this.broadcast.setFont(font, style, fontSize);
    }//GEN-LAST:event_fontJComboBoxItemStateChanged

    private void fontSizeJComboBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_fontSizeJComboBoxItemStateChanged
        this.fontSize=this.fontSizeJComboBox.getSelectedIndex()+9;
        this.inputMessageJTextPane.setFont(new Font(font,style,fontSize));
        this.broadcast.setFont(font, style, fontSize);
    }//GEN-LAST:event_fontSizeJComboBoxItemStateChanged

    private void italicJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_italicJButtonActionPerformed
        this.italicFlag=!this.italicFlag;
        if (this.italicFlag){
            this.style=Font.ITALIC;
        }else{
            this.style=Font.PLAIN;
        }
        this.inputMessageJTextPane.setFont(new Font(font,style,fontSize));
        this.broadcast.setFont(font, style, fontSize);
    }//GEN-LAST:event_italicJButtonActionPerformed

    private void boldJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_boldJButtonActionPerformed
        this.boldFlag=!this.boldFlag;
        if (this.boldFlag){
            this.style=Font.BOLD;
        }else{
            this.style=Font.PLAIN;
        }
        this.inputMessageJTextPane.setFont(new Font(font,style,fontSize));
        this.broadcast.setFont(font, style, fontSize);
    }//GEN-LAST:event_boldJButtonActionPerformed

    private void colorJComboBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_colorJComboBoxItemStateChanged
        switch (this.colorJComboBox.getSelectedItem().toString()){
            case "黑色":
                this.inputMessageJTextPane.setForeground(Color.black);
                this.broadcast.setFontColor(Color.black);
                break;
            case "红色":
                this.inputMessageJTextPane.setForeground(Color.red);
                this.broadcast.setFontColor(Color.red);
                break;
            case "蓝色":
                this.inputMessageJTextPane.setForeground(Color.blue);
                this.broadcast.setFontColor(Color.blue);
                break;
            case "橙色":
                this.inputMessageJTextPane.setForeground(Color.orange);
                this.broadcast.setFontColor(Color.orange);
                break;
            case "绿色":
                this.inputMessageJTextPane.setForeground(Color.green);
                this.broadcast.setFontColor(Color.green);
                break;
            default:
                //调用颜色选择窗口    
                    
        }
    }//GEN-LAST:event_colorJComboBoxItemStateChanged

    private void sendToJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sendToJButtonActionPerformed
        if (!this.inputMessageJTextPane.getText().equals("")){
            int index=this.onlineUsersJList.getSelectedIndex();
            if (index == -1){
                this.prompt("你还没有选择要发送的用户");
                return;
            }
            InetAddress inet=new ArrayList<OnlineUser>(this.broadcast.getOnlineUsers()).get(index).getInetAddress();
            this.broadcast.sendMessage(inet,this.inputMessageJTextPane.getText());
            this.inputMessageJTextPane.setText("");
        }
    }//GEN-LAST:event_sendToJButtonActionPerformed
    private void prompt(String message){        
        if (flag){
            flag = false;
            this.promptJLabel.setForeground(Color.red);
        }else{
            flag = true;
            this.promptJLabel.setForeground(Color.green);
        }
        this.promptJLabel.setText(message);
    }
    public void showMessage(String message){
        //消息协议message=protocolFlag+flag+type+flag+hostname+flag+nickname+flag+showFont(font)+flag+showColor(fontColor)+flag+text.trim();
        String[] split = message.split("#");
        String fontInfo[]= split[4].split(":");
        SimpleAttributeSet set = new SimpleAttributeSet();
        document = this.showMessageJTextPane.getStyledDocument();
        String msg;
        StyleConstants.setForeground(set, Color.blue);
        if (split[3].equals("") | split[3].equals("null")){
            msg=split[2]+" "+String.format("%tF %tT", Calendar.getInstance(),Calendar.getInstance())+"\n";
            try {
            document.insertString(document.getLength(), msg, set);            
            } catch (BadLocationException ex) {
                Logger.getLogger(ChatUI.class.getName()).log(Level.SEVERE, null, ex);
            }            
        }else{
            msg=split[3]+" & "+split[2]+" "+String.format("%tF %tT", Calendar.getInstance(),Calendar.getInstance())+"\n";
            try {
            document.insertString(document.getLength(), msg, set);            
            } catch (BadLocationException ex) {
                Logger.getLogger(ChatUI.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        //设置文字颜色
        StyleConstants.setForeground(set, this.getColor(split[5]));
        //设置字体
        StyleConstants.setFontFamily(set, fontInfo[0]);
        //设置字体风格
        if (Integer.parseInt(fontInfo[1]) == Font.PLAIN){
        StyleConstants.setItalic(set, false);
        StyleConstants.setBold(set, false);
        }else if (Integer.parseInt(fontInfo[1]) == Font.BOLD){
        StyleConstants.setItalic(set, false);
        StyleConstants.setBold(set, true);
        }else if (Integer.parseInt(fontInfo[1]) == Font.ITALIC){
        StyleConstants.setItalic(set, true);
        StyleConstants.setBold(set, false);
        }
        //设置字体大小
        StyleConstants.setFontSize(set, Integer.parseInt(fontInfo[2]));
        msg=split[6]+"\n\n";
        try {
        document.insertString(document.getLength(), msg, set);            
        } catch (BadLocationException ex) {
            Logger.getLogger(ChatUI.class.getName()).log(Level.SEVERE, null, ex);
        }
        this.showMessageJTextPane.setCaretPosition(this.showMessageJTextPane.getDocument().getLength());
    }
    private Color getColor(String showColor){
        Color fontColor;
        String RGB[] = showColor.split(":");
        fontColor=new Color(Integer.parseInt(RGB[0]),Integer.parseInt(RGB[1]),Integer.parseInt(RGB[2]));
        return fontColor;
    }
    /*
     * 用户列表全部刷新
     */
    public void flushOnlineUsersListShow(ArrayList onlineUsers) {
        DefaultListModel listModel = new DefaultListModel();
        Iterator<OnlineUser> it=onlineUsers.iterator();
        OnlineUser onlineUser;
        while (it.hasNext()){
            onlineUser=it.next();
            listModel.addElement(onlineUser.show());
        }        
        this.onlineUsersJList.setModel(listModel);
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton boldJButton;
    private javax.swing.JButton closeJButton;
    private javax.swing.JComboBox colorJComboBox;
    private javax.swing.JButton flushJButton;
    private javax.swing.JComboBox fontJComboBox;
    private javax.swing.JComboBox fontSizeJComboBox;
    private javax.swing.JScrollPane inputMessageJScrollPane;
    private javax.swing.JTextPane inputMessageJTextPane;
    private javax.swing.JButton italicJButton;
    private javax.swing.JPanel jPanel;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField nicknameJTextField;
    private javax.swing.JList onlineUsersJList;
    private javax.swing.JLabel promptJLabel;
    private javax.swing.JButton sendJButton;
    private javax.swing.JButton sendToJButton;
    private javax.swing.JScrollPane showMessageJScrollPane;
    private javax.swing.JTextPane showMessageJTextPane;
    // End of variables declaration//GEN-END:variables

    
}
